<?php
	$message = "";

	include("load-settings.php");

	if(isset($_POST['posted']))
	{
		if(!isset($_POST['acceptance']))
		{
			$message = "You must accept the terms and conditions.";
		}
		else
		{
			

			$name = mysql_real_escape_string($_POST['applicantname']);
			$skype = mysql_real_escape_string($_POST['skype']);
			$email = mysql_real_escape_string($_POST['email']);
			$lolking = mysql_real_escape_string($_POST['lolking']);
			$region = mysql_real_escape_string($_POST['region']);
			$elo = mysql_real_escape_string($_POST['elo']);
			$ip_address = mysql_real_escape_string($_POST['ip_address']);
			$interested = "";

			if(isset($_POST['interested']))
			{
				foreach($_POST['interested'] as $check) {
					$interested .= $check.", ";
				}
			}

			if(strlen($interested) > 0)
				$interested = substr($interested, 0, strlen($interested) - 2);

			$feedback = mysql_real_escape_string($_POST['form_feedback']);
			$comments = mysql_real_escape_string($_POST['form_comments']);

			if($name != "" && $skype != "" && $email != "" && $lolking != "" && $region != "" && $elo != "" && $interested != "")
			{
				$result = mysql_query("SELECT * FROM booster_application WHERE email = '$email'");

				if(mysql_num_rows($result) == 0)
				{
				
					mysql_query("INSERT INTO booster_application (name, skype, email, lolking, region, elo, interested, feedback, comments, timestamp, ip_address) VALUES ('$name', '$skype', '$email', '$lolking', '$region', '$elo', '$interested', '$feedback', '$comments', ".time().", '$ip_address')") or die(mysql_error());

					$pass = substr(md5(rand()), 0, 7);

					mysql_query("INSERT INTO user (paypal, username, password, type) VALUES ('$email', '$skype', '$pass', 0)") or die(mysql_error());

					$to = $email;
					$subject = "ELO Coach application received.";
					$message = str_replace("[password]", $pass, $booster_signup_email);
					$message = str_replace("\n", "\r\n", $message);

					$headers = 'From: admin@elocoach.com' . "\r\n" .
					'Reply-To: admin@elocoach.com' . "\r\n" .
					'X-Mailer: PHP/' . phpversion();

					mail($to, $subject, $message, $headers);

					$message = "Successfully applied. We have sent you an email with instructions to login.";
				}
				else
				{
					$message = "You have already applied using this form. We will review your application and get back to you as soon as possible.";
				}
			}
			else
			{
				$message = "All fields are required.";
			}
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,800">
<meta charset="utf-8">
<link rel="icon" href="http://veteranboosters.com/orders/images/favicon.ico" type="image/x-icon"/>
<link rel="shortcut icon" href="http://veteranboosters.com/orders/images/favicon.ico" type="image/x-icon"/>
  <!-- Always force latest IE rendering engine or request Chrome Frame -->
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<title>Booster application</title>
<link href="stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="javascripts/application.js" type="text/javascript"></script>
</head>
<body>
<div class="container">
  
<div class="span10">


  <div class="padded">
<?php 
if($message == "")
	echo $booster_application; 
else
{
	if($message != "You have already applied using this form. We will review your application and get back to you as soon as possible.")
		echo $app_confirmation;
	else
		echo $message;
}
?>
<?php
	if($message == "")
	{
		?>
<div class="login box" style="margin-top: 80px;">
<div class="box-header">
        <span class="title">Application form</span>
      </div>
	  <div class="box-content padded">
<form action="" method="post" class="separate-sections">
<hr>
<p><b>First &amp; Last Name</b><br>
    <span class="wpcf7-form-control-wrap name"><input type="text" name="applicantname" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" required></span> </p>
<p><b>Skype Username</b><br>
    <span class="wpcf7-form-control-wrap skype"><input type="text" name="skype" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" required></span> </p>
<p><b>Paypal Payment Email</b><br>
    <span class="wpcf7-form-control-wrap email"><input type="text" name="email" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" required></span> </p>
<input type="hidden" name="ip_address" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" >
<p><b>Your Lolking.net Profile Link</b><br>
    <span class="wpcf7-form-control-wrap lolking"><input type="text" name="lolking" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" required></span> </p>
<p><b>Regions</b><br>
     <span class="wpcf7-form-control-wrap region"><input type="text" name="region" value="" size="40" class="wpcf7-form-control wpcf7-text wpcf7-validates-as-required" required placeholder="Please list all regions you can do."></span></p>
<p><b>Highest Boostable Division?</b><br>
   <span class="wpcf7-form-control-wrap elo"><select name="elo" class="wpcf7-form-control wpcf7-select wpcf7-validates-as-required" required><option value="">---</option><option value="Platinum V">Platinum V</option><option value="Platinum IV">Platinum IV</option><option value="Platinum III">Platinum III</option><option value="Platinum II">Platinum II</option><option value="Platinum I">Platinum I</option><option value="Diamond V">Diamond V</option><option value="Diamond IV">Diamond IV</option><option value="Diamond III">Diamond III</option><option value="Diamond II">Diamond II</option><option value="Diamond I">Diamond I</option><option value="Challenger">Challenger</option></select></span> </p>
<p><b>Interested In</b><br>
    <span class="wpcf7-form-control-wrap interested"><span class="wpcf7-form-control wpcf7-checkbox"><span class="wpcf7-list-item"><input type="checkbox" name="interested[]" value="Solo ELO Boosting">&nbsp;<span class="wpcf7-list-item-label">Solo ELO Boosting</span></span><br><span class="wpcf7-list-item"><input type="checkbox" name="interested[]" value="Duo Queue w/ Customer">&nbsp;<span class="wpcf7-list-item-label">Duo Queue w/ Customer</span></span><br><span class="wpcf7-list-item"><input type="checkbox" name="interested[]" value="Coaching">&nbsp;<span class="wpcf7-list-item-label">Coaching</span></span></span></span></p>
<p><b>Forum Feedback or Vouches</b><br>
    <span class="wpcf7-form-control-wrap otherfb2"><textarea name="form_feedback" style = "width: 600px" rows="10" class="wpcf7-form-control wpcf7-textarea wpcf7-validates-as-required" aria-required="true" aria-invalid="false" placeholder="If you do not have feedback / vouches, put none."></textarea></span> </p>
<p><b>Notes or Comments</b><br>
   <span class="wpcf7-form-control-wrap reason"><textarea name="form_comments"  style = "width: 600px" rows="10" class="wpcf7-form-control wpcf7-textarea" aria-invalid="false" placeholder="Know one of our boosters? Please indicate that here for priority application processing."></textarea></span></p>
<p><b>I have read the above information on this page and agree to the terms above and those found on the TOS &amp; Privacy Policy.</b></p>
<p>
I agree to all information shown on this page <span class="wpcf7-form-control-wrap acceptance-358"><input type="checkbox" name="acceptance" value="1" class="wpcf7-form-control wpcf7-acceptance" required></span></p>
<input type = "hidden" name = "posted" value = "1" />
<p><input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit"></p>
<div class="wpcf7-response-output"><?php echo $message; ?></div></form>
</div></div>
<?php
	}
		?>
</div></div></div>
</body>
</html>